package lib

import (
	"RMS/app/shop/model"
	"RMS/common"
	"RMS/common/db"
	"context"
	jsoniter "github.com/json-iterator/go"
	"log"
)

func ImplUpdateTable(ctx context.Context, req *model.UpdateTableReq) *model.UpdateTableResp {
	resp := &model.UpdateTableResp{}
	d := db.NewRmsDBRequest(ctx)
	d = d.Table(db.PmsTable)
	b, _ := jsoniter.Marshal(req)
	itemMap := make(map[string]interface{})
	jsoniter.Unmarshal(b, &itemMap)
	if err := d.Where("id = ?", req.Id).Updates(itemMap).Error; err != nil {
		log.Printf("更新失败 err:=%v\n", err.Error())
		resp.Status = common.ErrCode
		resp.Message = common.UpdErrMessage
		return resp
	}
	resp.Status = common.SuccessCode
	resp.Message = common.SuccessMessage
	return resp
}
